<?php
/**
 * 关键字过滤系统
 */

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');


if ($_REQUEST['act'] == 'default')
{

	$content = file_get_contents('word_filter.txt');
	$content = split('[{\.}]', $content);
	$words = array();
	for($i=1; $i+3<count($content);$i+=6) {
		$words[] = array('word'=>$content[$i],'filtertype'=>$content[$i+2],'wordtype'=>$content[$i+4]);
	}

	$smarty->assign('ur_here',      $_LANG['word_filter']);
	$smarty->assign('words',        $words);
    $smarty->display('word_filter.htm');
}
//批量添加
elseif ($_REQUEST['act'] == 'upload')
{
	$file = $_FILES['newrule'];

	if( $file['error'] > 0 ) {
		echo 'file broken';
		exit;
	} 

	//文件后缀
	$extend =explode("." , $file['name']);
	$ext = $extend[count($extend)-1];
	if($ext != 'txt'){
		echo '文件类型错误.';
		exit;
	}

	if( is_uploaded_file( $file['tmp_name'] ) ) {
		$content = file_get_contents($file['tmp_name']);
		if( file_put_contents('word_filter.txt',"\r\n" . iconv ( 'gb2312' , 'utf-8' , $content),FILE_APPEND) ){
			echo '上传成功'."<a href='word_filter.php?act=default'>返回</a>";
		}
		exit;
	}else{
		echo '上传失败';
		exit;
	}
}

?>